package com.hurui.xiaoming.activity.me;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hurui.xiaoming.R;
import com.hurui.xiaoming.activity.BaseActivity;
import com.hurui.xiaoming.adapter.ProfitAdapter;
import com.hurui.xiaoming.bean.Li_Personal_Result;
import com.hurui.xiaoming.bean.Li_profit_Result;
import com.hurui.xiaoming.myconfig.PamaryKeys;
import com.hurui.xiaoming.utils.WriteReadSharedPrefs;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyProfitActivity extends BaseActivity {

    private ImageView back_iv ;
    private TextView money_tv ;
    private RecyclerView profit_rv ;

    private ProfitAdapter adapter ;
    private Li_Personal_Result.DataBean dataBean;
    private Map<String ,String> map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_profit);
        dataBean = (Li_Personal_Result.DataBean) getIntent().getSerializableExtra(PamaryKeys.DATABEAN);

        map=new HashMap<>();
        tintManager.setStatusBarTintColor(R.color.systembartintColor2);
        initView();
        initAdapter();
        initAction();
    }

    private void initAdapter(){
        adapter = new ProfitAdapter(this);
        profit_rv.setLayoutManager(new LinearLayoutManager(this));
        profit_rv.setAdapter(adapter);

    }

    @Override
    public void initView() {
        map.put(PamaryKeys.UI_ID, WriteReadSharedPrefs.readUserID(mContext)+"");

        back_iv = (ImageView) findViewById(R.id.back_iv);
        money_tv = (TextView) findViewById(R.id.money_tv);
        profit_rv = (RecyclerView) findViewById(R.id.profit_rv);
        money_tv.setText(dataBean.getProfit());
        initAdapter();
        apiSevice.onHttp_profit(map).enqueue(new Callback<Li_profit_Result>() {
            @Override
            public void onResponse(Call<Li_profit_Result> call, Response<Li_profit_Result> response) {
                if (response.body().getStatus().equals("sucess")){
                    adapter.notifyData(response.body().getData());

                }
            }

            @Override
            public void onFailure(Call<Li_profit_Result> call, Throwable t) {

            }
        });
    }

    @Override
    public void initAction(){
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onFinish();
            }
        });
    }
}
